/**
 * Captain
 * © 2018 Captain copyright，All rights reserved.
 * http://www.sccaptain.com.cn
 * 
 * JAVA : 8
 * 文  件  名: CommInfoController.java
 * 创  建  人: QinYoubin (qin.youbin@sccaptain.com.cn)
 * 创建时间: 2018年4月26日 下午2:13:55
 * 版         本: 1.0.0
 * 备         注:
 * 修订历史:
 */
package com.material.c2c.web.commodity.controller;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.cpt.framework.web.JsonResult;
import com.material.c2c.commodity.model.CommDetailDTO;
import com.material.c2c.commodity.service.CommInfoService;
import com.material.c2c.web.commodity.model.CommQuery;

/**
 * 商品信息控制层 
 * @since 1.0
 * @version 1.0
 * @author QinYoubin (qin.youbin@sccaptain.com.cn)
 */
@RestController
@RequestMapping("/commodity")
public class CommInfoController {
  @Resource
  private CommInfoService commInfoService;
  
  @PostMapping("/add")
  public JsonResult add(@RequestBody CommDetailDTO dto) {
    commInfoService.add(dto.getSpxx(), dto.getSpjs(),dto.getTpList());
    return JsonResult.SUCCEED;
  }
  @PostMapping("/update")
  public JsonResult update(@RequestBody CommDetailDTO dto) {
    commInfoService.update(dto.getSpxx(), dto.getSpjs());
    return JsonResult.SUCCEED;
  }
  @GetMapping("/delete/{id}")
  public JsonResult delete(@PathVariable String id) {
    return JsonResult.success(commInfoService.delete(id));
  }
  @GetMapping("/getOne/{id}")
  public JsonResult getOne(@PathVariable String id) {
    return JsonResult.success(commInfoService.getOne(id));
  }
  @PostMapping("/search")
  public JsonResult search(@RequestBody CommQuery query) {
    return JsonResult.success(commInfoService.list(query.getKey(),query.getFl(), query.getPageable()));
  }
}